$TITLE  GTAPinGAMS -- Static Multiregional Core Model in MPSGE Syntax

*	Note:

*		This is the model implemented in MPSGE.

*		This implementation accomodates both constant-elasticity of
*		transformation between production for domestic and export
*		markets (eta < +INF), and perfect substitution between 
*		those markets (eta=+INF).

*		Variables, equations and GAMS keywords are in UPPER case.
*		Sets and parameters are in lower case.

*	Read the dataset using the standard routine:

set	i(*), r(*), d(*), f(*);
$gdxin 'mge.gdx'
$load i r d f

ALIAS (i,j), (r,s), (r,rr);

SET     num(R)  Identifies the numeraire region,
	cgd(i)  Identifies the investment good /cgd/;


PARAMETER
	eta	Elasticity of transformation - domestic vs. exports,
	esubdm	Elasticity of substitution - domestic vs. imports,
	esubmm  Elasticity of substitution - imports,

        vim(i,r)        Total value of imports (gross tariff)
        vxm(i,r)        Value of export (net excise tax)
        vdm(i,r)        Value of domestic output (net excise tax)
        vdfm(i,r)       Aggregate intermediate demand (domestic)
        vifm(i,r)       Aggregate intermediate demand (imported)

        vom(i,r)        Aggregate output value (gross of tax)
        vgm(i,r)        Public expenditures
        vpm(i,r)        Private expenditures
        vg(r)           Total value of public expenditure
        vp(r)           Total value of private expenditure
	vi(r)		Total value of investment
        vt              Value of trade markups
        vb(r)           Net capital inflows

        evoa(f,r)       Value of factor income

        va(d,i,r)       Armington supply
        vd(d,i,r)       Domestic supply
        vm(d,i,r)       Imported supply

        ty(i,r)         Output tax
        ti(j,i,r)       Intermediate input tax
        tf(f,i,r)       Factor tax
        tx(i,s,r)       Export tax rate (defined on a net basis)
        tm(i,s,r)       Import tariff rate
        tg(i,r)         Tax rates on government demand
        tp(i,r)         Tax rate on private demand

        vafm(j,i,r)     Aggregate intermediate inputs
        vfm(f,i,r)      Value of factor inputs (net of tax)
        vtwr(i,r,s)     Transport services
        vxmd(i,r,s)     Value of commodity trade (fob - net export tax)
        vst(i,r)        Value of international transport sales
        evoa(f,r)       Value of factor income

        pmx0(i,s,r)     Reference price of imports,
        pmt0(i,s,r)     Reference price of transport services,
        pg0(i,r)        Reference price of government demand,
        pc0(i,r)        Reference price for private demand,
        py0(i,r)        Reference output price (domestic or export),
        pai0(j,i,r)     Reference price for intermediate inputs,
        pf0(f,i,r)      Reference price for factor inputs;

$load	num eta esubdm esubmm 
$load	vom vim va vdm vxm evoa vafm vfm vd vm 
$load	vtwr vg vgm vp vpm vt vst vb vi vxmd 
$load	pf0 pmx0 pmt0 pg0 pc0
$load	ty ti tf tx tm tg tp

PARAMETER	vxb(i,s,r)	Bilateral trade flows;

vxb(i,s,r) = vxmd(i,s,r)*pmx0(i,s,r) + vtwr(i,s,r)*pmt0(i,s,r);

$ONTEXT

$MODEL:GTAP

$SECTORS:
        C(r)                    ! Private consumption
        G(r)                    ! Public provision
        Y(i,r)$vom(i,r)         ! Output
	B(i,s,r)$vxb(i,s,r)	! Bilateral trade flow
        M(i,r)$vim(i,r)         ! Import aggregation
        A(d,i,r)$va(d,i,r)      ! Armington aggregation of domestic and imports
        YT                      ! Transport 

$COMMODITIES:
        PC(r)			! Private demand
        PG(r)			! Public provision
        PD(i,r)$vdm(i,r)	! Domestic price
	PB(i,s,r)$vxb(i,s,r)	! Price level of bilateral import
        PX(i,r)$vxm(i,r)	! Export price
        PM(i,r)$vim(i,r)	! Import price
        PA(d,i,r)$va(d,i,r)	! Armington composite price
        PF(f,r)$evoa(f,r)	! Factor price
        PT                      ! Transport services

$CONSUMERS:
       RA(r)           ! Representative agent

*       Production:

$PROD:Y(i,r)$(vom(i,r)>0)  S:0  T:eta  va:1
        O:PD(i,r)	Q:vdm(i,r)    A:RA(r) T:ty(i,r)
        O:PX(i,r)	Q:vxm(i,r)    A:RA(r) T:ty(i,r)
        I:PA("i",j,r)	Q:vafm(j,i,r) A:RA(r) T:ti(j,i,r) 
        I:PF(f,r)	Q:vfm(f,i,r)  P:pf0(f,i,r) A:RA(r) T:tf(f,i,r) va:

*       Armington aggregation over domestic versus imports:

$PROD:A(d,i,r)$va(d,i,r)  S:esubdm
        O:PA(d,i,r)	Q:va(d,i,r)
        I:PD(i,r)	Q:vd(d,i,r)
        I:PM(i,r)	Q:vm(d,i,r)

*       Armington aggregation across imports from different countries:

$PROD:M(i,r)$(vim(i,r)>0)   S:esubmm   
        O:PM(i,r)       Q:vim(i,r)
	I:PB(i,s,r)	Q:vxb(i,s,r)

$PROD:B(i,s,r)$(vxmd(i,s,r) > 0)  s:0
	O:PB(i,s,r)	Q:vxb(i,s,r)
        I:PX(i,s)       Q:vxmd(i,s,r)  P:pmx0(i,s,r)	
+                       A:RA(S) T:tx(i,s,r) A:RA(r) T:(tm(i,s,r)*(1+tx(i,s,r)))
        I:PT	        Q:vtwr(i,s,r)  P:pmt0(i,s,r)	
+			A:RA(r) T:tm(i,s,r)
	
*       Demand for public output:

$PROD:G(r)  S:1
        O:PG(r)         Q:vg(r)
        I:PA("g",i,r)   Q:vgm(i,r)  P:pg0(i,r)  A:RA(r) T:tg(i,r) 

*       Private consumption:

$PROD:C(r)  S:1
        O:PC(r)         Q:vp(r)
        I:PA("c",i,r)   Q:vpm(i,r)  P:pc0(i,r)  A:RA(r) T:tp(i,r)

*       Inter-national transport services (Cobb-Douglas):

$PROD:YT  S:1
        O:PT		Q:vt
        I:PX(i,r)	Q:vst(i,r)

*       Final demand over consumption, savings and government 
*       services (Cobb-Douglas):

$DEMAND:RA(r)  
        E:PF(f,r)	Q:evoa(f,r)
        E:PC(num)	Q:vb(r)
        E:PD(cgd,r)	Q:-vi(r)
        E:PG(r)		Q:-vg(r)
        D:PC(r)		Q:vp(r)

$OFFTEXT
$SYSINCLUDE mpsgeset GTAP

PC.FX(num) = 1;

*	Check the benchmark:

GTAP.ITERLIM = 0;
$INCLUDE GTAP.GEN
SOLVE GTAP USING MCP;

*	Perform a free-trade liberalization experiment:

tm(i,r,s) = 0;
tx(i,r,s) = 0;
GTAP.ITERLIM = 20000;
$INCLUDE GTAP.GEN
SOLVE GTAP USING MCP;
